package com.sgb.member.ui.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.text.TextUtils;
import android.view.View;

import com.sgb.member.BR;
import com.sgb.member.MemberConfig;
import com.sgb.member.R;
import com.sgb.member.databinding.ItemPromotionInfoBinding;
import com.sgb.member.entity.PromotionInfoBean;
import com.sgb.member.util.MLocationUtil;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.MToast;
import com.swgk.core.util.PointUtils;
import com.swgk.core.util.StringUtil;

import java.text.DecimalFormat;
import java.util.List;

public class PromotionInfoAdapter extends BaseRecycleAdapter<PromotionInfoBean> {
    private static final int PROMOTE_GOODS = 2;
    private final DecimalFormat df = new DecimalFormat("#.00");
    public PromotionInfoAdapter(Context context, List<PromotionInfoBean> datas) {
        super(context, R.layout.item_promotion_info, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, PromotionInfoBean entity) {
        holder.setBinding(BR.itemBean, entity);
        ItemPromotionInfoBinding binding = (ItemPromotionInfoBinding) holder.getmBinding();
        binding.contentView.setOnClickListener(v -> {
            if (!TextUtils.isEmpty(entity.getComNo())) {
                MemberConfig.getInstance().startWebsiteInfo(context, entity.getComNo(), 1);
            } else {
                MToast.showToast(context, "店铺No为空");
            }
        });
        if (entity.getPromoteStatus() == PROMOTE_GOODS) {
            binding.imgCx.setVisibility(View.VISIBLE);
            binding.tvLastPrice.setVisibility(View.VISIBLE);
            binding.tvLastPrice.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
            binding.tvLastPrice.setText(String.format("￥%s/%s", df.format(entity.getPrice()), entity.getUnit()));
            StringUtil.setNoddleLine(df.format(entity.getPrice()));
            binding.tvSpec.setText(StringUtil.setMoney(PointUtils.price(Double.parseDouble(entity.getPromotePrice()))));
        } else {
            binding.imgCx.setVisibility(View.GONE);
            binding.tvLastPrice.setVisibility(View.GONE);
            binding.tvSpec.setText(StringUtil.setMoney(PointUtils.price(entity.getPrice())));
        }
    }
}
